﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data.OracleClient;
using System.Configuration;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using PDAWebService;
using PDAWebService.Entity;
using PDADataAccess;
using System.Linq;

namespace PDAService
{
    /// <summary>
    /// PDAService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class PDAService : System.Web.Services.WebService
    {
        #region PDA

        #region Protery
        /// <summary>
        /// 验证Soap头携带
        /// </summary>
        public Authentication authentication;


        public static NLog.Logger logger = NLog.LogManager.GetLogger("[PDAService]");

        #endregion

        #region Controuct
        /// <summary>
        /// 服务构造参数创建数据访问对象
        /// </summary>
        public PDAService()
        {
        }
        #endregion

        #region 校正服务器时间

        [WebMethod]
        [SoapHeader("authentication")]
        public DateTime GetServerSyncTime()
        {
            return DateTime.Now;
        }

        #endregion

        #region 更新PDA程序
        /// <summary>
        /// 获取安装包
        /// </summary>
        /// <param name="hasPatch">是否需要更新</param>
        /// <returns></returns>      
        [WebMethod]
        [SoapHeader("authentication")]
        public byte[] GetIntallPatch(string oldVersion, ref string newVersion)
        {
            byte[] packByte = null;
            if (WSAuthentication.Principal != null && WSAuthentication.Principal.Identity.Name == "Anoymity")
            {
                HttpException soapEx = new HttpException(403, "服务不允许匿名访问，无权访问此页面!");
                throw soapEx;
            }
            try
            {
                if (!IsNeedUpdate(oldVersion, ref newVersion))
                {
                    // 不需要更新
                    newVersion = "N";
                    return null;
                }

                string updateDirectoryPath = AppDomain.CurrentDomain.BaseDirectory + "Update";

                if (!Directory.Exists(updateDirectoryPath))
                {
                    Directory.CreateDirectory(updateDirectoryPath);
                }
                string[] filesCab = Directory.GetFiles(updateDirectoryPath, "*.cab");

                if (filesCab != null && filesCab.Length > 0)
                {
                    string strFileName = Path.Combine(updateDirectoryPath, filesCab[0]);

                    if (File.Exists(strFileName))
                    {
                        logger.Debug("GetIntallPatch更新包文件存在:" + strFileName);
                        try
                        {
                            logger.Debug("GetIntallPatch更新包获取开始!");
                            ///打开现有文件以进行读取。
                            FileStream s = File.OpenRead(strFileName);
                            packByte = ConvertStreamToByteBuffer(s);
                            s.Close();
                            logger.Debug("GetIntallPatch更新包获取成功!");
                            return ConvertZip.Compress(packByte);
                        }
                        catch (Exception ex)
                        {
                            logger.ErrorException("GetIntallPatch更新包返回Null!", ex);
                            return packByte = null;
                        }
                    }
                }
                logger.Debug("GetIntallPatch更新包返回Null!");
            }
            catch (Exception ex)
            {
                logger.ErrorException("GetIntallPatch获取更新包的过程中产生异常!", ex);
            }
            return packByte;
        }

        /// <summary>
        /// 或许是否需要更新安装包
        /// </summary>
        /// <param name="oldVersion"></param>
        /// <returns></returns>
        private bool IsNeedUpdate(string oldVersion, ref string newVersion)
        {
            bool isNeedUpdate = false;
            try
            {
                newVersion = ConfigurationManager.AppSettings["setupVer"];
                logger.Debug("IsNeedUpdate 服务端配置的版本号是:" + newVersion + "/" + oldVersion);

                if (newVersion.Length > 0 && oldVersion != newVersion)
                {
                    logger.Debug("IsNeedUpdate 客户端需要进行更新!");
                    isNeedUpdate = true;
                }
            }
            catch
            {
                isNeedUpdate = false;
            }
            return isNeedUpdate;
        }

        /// <summary>
        /// 将内存流内容转换为字节数组
        /// </summary>
        /// <param name="theStream"></param>
        /// <returns></returns>
        private byte[] ConvertStreamToByteBuffer(Stream theStream)
        {
            int b1;
            MemoryStream tempStream = new MemoryStream();
            while ((b1 = theStream.ReadByte()) != -1)
            {
                tempStream.WriteByte(((byte)b1));
            }
            return tempStream.ToArray();
        }
        #endregion
        #endregion PDA

        #region 获取部门档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取部门档案
        /// </summary>
        /// <param name="DepCode">部门编号</param>
        /// <param name="DepName">部门名称</param>
        public ResponseBase<Department> GetDepartments(string DepCode, string DepName)
        {
            ResponseBase<Department> Response = new ResponseBase<Department>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";

            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<Department> iqueryable = UFdataContext.Departments;

                if (DepCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CDepCode.Contains(DepCode));
                }
                if (DepName.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CDepName.Contains(DepName));
                }

                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetDepartments 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取职员档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取职员档案
        /// </summary>
        /// <param name="Fuzzyed">是否模糊查询</param>
        /// <param name="PersonCode">职员编码</param>
        /// <param name="PersonName">职员名称</param>
        public ResponseBase<Person> GetPersons(Boolean Fuzzyed, string PersonCode, string PersonName)
        {
            ResponseBase<Person> Response = new ResponseBase<Person>();
            Response.Lists = new List<Person>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";

            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<Person> iqueryable = UFdataContext.People;
                // 是否模糊查询
                if (Fuzzyed)
                {
                    if (PersonCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CPersonCode.Contains(PersonCode));
                    }


                    if (PersonName.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CPersonName.Contains(PersonName));
                    }

                }
                else
                {
                    if (PersonCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CPersonCode == PersonCode);
                    }


                    if (PersonName.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CPersonName == PersonName);
                    }
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetPersons 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取仓库档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取仓库档案
        /// </summary>
        /// <param name="Fuzzyed">是否模糊查询</param>
        /// <param name="WhCode">仓库编码</param>
        /// <param name="WhName">仓库名称</param>
        public ResponseBase<Warehouse> GetWarehouses(Boolean Fuzzyed, string WhCode, string WhName)
        {
            ResponseBase<Warehouse> Response = new ResponseBase<Warehouse>();
            Response.Lists = new List<Warehouse>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";
            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<Warehouse> iqueryable = UFdataContext.Warehouses;
                // 是否模糊查询
                if (Fuzzyed)
                {
                    if (WhCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CWhCode.Contains(WhCode));
                    }


                    if (WhName.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CWhName.Contains(WhName));
                    }

                }
                else
                {
                    if (WhCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CWhCode == WhCode);
                    }


                    if (WhName.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CWhName == WhName);
                    }
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetWarehouses 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取商品档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取商品档案
        /// </summary>
        /// <param name="Fuzzyed">模糊查询</param>
        /// <param name="BarCode">条形码</param>
        /// <param name="InvCode">商品编码</param>
        /// <param name="InvName">商品名称</param>
        public ResponseBase<Inventory> GetInventorys(Boolean Fuzzyed, string BarCode, string InvCode, string InvName)
        {
            ResponseBase<Inventory> Response = new ResponseBase<Inventory>();
            Response.ErrorInfo = new ErrorMessage();
            Response.Lists = new List<Inventory>();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";
            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<Inventory> iqueryable = UFdataContext.Inventories;
                // 是否模糊查询
                if (Fuzzyed)
                {
                    if (BarCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CBarCode.Contains(BarCode));
                    }
                    if (InvCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CInvCode.Contains(InvCode));
                    }

                    if (InvName.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CInvName.Contains(InvName));
                    }

                }
                else
                {
                    if (BarCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CBarCode == BarCode);
                    }

                    if (InvCode.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CInvCode == InvCode);
                    }

                    if (InvName.Trim().Length > 0)
                    {
                        iqueryable = iqueryable.Where(c => c.CInvName == InvName);
                    }
                }

                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetInventorys 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取商品类别档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取商品类别档案
        /// </summary>
        /// <param name="InvCCode">类别编号</param>
        /// <param name="InvCName">类别名称</param>
        public ResponseBase<InventoryClass> GetInvClass(string InvCCode, string InvCName)
        {
            ResponseBase<InventoryClass> Response = new ResponseBase<InventoryClass>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";

            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<InventoryClass> iqueryable = UFdataContext.InventoryClasses;
                if (InvCCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CInvCCode.Contains(InvCCode));
                }
                if (InvCName.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CInvCName.Contains(InvCName));
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetInvClass 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取客户档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取客户档案
        /// </summary>
        /// <param name="CusCode">客户编号</param>
        /// <param name="CusName">客户名称</param>
        public ResponseBase<Customer> GetCustomer(string CusCode, string CusName)
        {
            ResponseBase<Customer> Response = new ResponseBase<Customer>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";

            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<Customer> iqueryable = UFdataContext.Customers;
                if (CusCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CCusCode.Contains(CusCode));
                }
                if (CusName.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CCusName.Contains(CusName));
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetCustomer 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取客户类别档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取客户类别档案
        /// </summary>
        /// <param name="CusCCode">类别编号</param>
        /// <param name="CusCName">类别名称</param>
        public ResponseBase<CustomerClass> GetCustomerClass(string CusCCode, string CusCName)
        {
            ResponseBase<CustomerClass> Response = new ResponseBase<CustomerClass>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";

            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<CustomerClass> iqueryable = UFdataContext.CustomerClasses;
                if (CusCCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CCCName.Contains(CusCCode));
                }
                if (CusCName.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CCCName.Contains(CusCName));
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetCustomerClass 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取供应商档案

        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取供应商档案
        /// </summary>
        /// <param name="VenCode">供应商编号</param>
        /// <param name="VenName">供应商名称</param>
        public ResponseBase<Vendor> GetVendor(string VenCode, string VenName)
        {
            ResponseBase<Vendor> Response = new ResponseBase<Vendor>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";

            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<Vendor> iqueryable = UFdataContext.Vendors;
                if (VenCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CVenCode.Contains(VenCode));
                }
                if (VenName.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CVenName.Contains(VenName));
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetVendor 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取供应商类别档案
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取供应商类别档案
        /// </summary>
        /// <param name="VenCCode">类别编号</param>
        /// <param name="VenCName">类别名称</param>
        public ResponseBase<VendorClass> GetVendorClass(string VenCCode, string VenCName)
        {
            ResponseBase<VendorClass> Response = new ResponseBase<VendorClass>();
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";

            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<VendorClass> iqueryable = UFdataContext.VendorClasses;
                if (VenCCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CVCCode.Contains(VenCCode));
                }
                if (VenCName.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CVCName.Contains(VenCName));
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetVendorClass 方法异常", ex);
            }
            return Response;
        }
        #endregion

        #region 获取单据编号
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取单据编号，销售发货单的CardNumber
        /// </summary>
        /// <param name="CardNumber">单据类型编码</param>
        /// <param name="return">该单据编号</param>
        public ResponseString GetVouchCode(int CardNumber)
        {
            ResponseString Response = new ResponseString();
            Response.Value = "";
            Response.ErrorInfo = new ErrorMessage();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";
            string VouchCode = "";
            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<VoucherNumber> iqueryable = UFdataContext.VoucherNumbers;
                if (CardNumber > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CardNumber == CardNumber.ToString());
                }
                List<VoucherNumber> VNumbers = iqueryable.ToList();

                if (VNumbers.Count > 0)
                {
                    string dSeed = DateTime.Today.ToString("yyyy-MM-dd");
                    string Num = "";

                    IQueryable<VoucherHistory> iqVHistory = UFdataContext.VoucherHistories;
                    iqVHistory = iqVHistory.Where(c => c.CardNumber == CardNumber.ToString());
                    iqVHistory = iqVHistory.Where(c => c.CContentRule == VNumbers[0].GlideRule);
                    iqVHistory = iqVHistory.Where(c => c.CContent == VNumbers[0].Glide);
                    iqVHistory = iqVHistory.Where(c => c.CSeed == dSeed);
                    List<VoucherHistory> VHistorys = iqVHistory.ToList();
                    if (VHistorys.Count > 0)
                    {
                        Num = VHistorys[0].CNumber;
                        int NumLen = Num.Length;
                        for (int I = NumLen; I < 3; I++)
                        {
                            Num = "0" + Num;
                        }
                        VouchCode = dSeed + Num;
                    }
                    else
                    {
                        VouchCode = dSeed + "001";
                    }
                    Response.Value = VouchCode;
                }
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetVouchCode 方法异常", ex);
            }
            return Response;

        }
        #endregion

        #region 获取销售发货单
        [WebMethod]
        [SoapHeader("authentication")]
        /// <summary>
        /// 获取单据数据
        /// </summary>
        /// <param name="cDLCode">单据号码</param>
        /// <param name="dDateS">单据开始日期</param>
        /// <param name="dDateE">单据结束日期</param>
        public ResponseBase<DispatchList1> GetDispatchList1(string cDLCode, DateTime dDateS, DateTime dDateE)
        {
            ResponseBase<DispatchList1> Response = new ResponseBase<DispatchList1>();
            Response.ErrorInfo = new ErrorMessage();
            Response.Lists = new List<DispatchList1>();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";
            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<DispatchList1> iqueryable = UFdataContext.DispatchList1;
                if (cDLCode.Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CDLCode == cDLCode);
                }
                else
                {
                    iqueryable = iqueryable.Where(c => c.DDate <= dDateS);
                    iqueryable = iqueryable.Where(c => c.DDate <= dDateE);
                }
                Response.Lists = iqueryable.ToList();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("GetDispatchList1 方法异常", ex);
            }

            return Response;
        }
        #endregion

        #region 更新销售发货单

        [WebMethod]
        [SoapHeader("authentication")]
        public ResponseBoolean SetDispatchList1(DispatchList1 oDispatchList)
        {
            ResponseBoolean Response = new ResponseBoolean();
            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                UFdataContext.Add(oDispatchList);
                UFdataContext.SaveChanges();
            }
            catch (Exception ex)
            {
                Response.ErrorInfo.ErrorCode = -1;
                Response.ErrorInfo.ErrorMsg = ("出错原因：" + ex.Message);
                logger.ErrorException("SetDispatchList1 方法异常", ex);
            }

            return Response;
        }
        #endregion

        [WebMethod]
        [SoapHeader("authentication")]
        public ResponseBase<SysUser> GetSysUser()
        {
            ResponseBase<SysUser> Response = new ResponseBase<SysUser>();
            Response.ErrorInfo = new ErrorMessage();
            Response.Lists = new List<SysUser>();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";
            try
            {
                PDAEntityDiagrams UFdataContext = new PDAEntityDiagrams();
                IQueryable<SysUser> iqueryable = UFdataContext.SysUsers;

                Response.Lists = iqueryable.ToList();

            }
            catch (Exception ex)
            {

            }

            return Response;
        }





        /// <summary>
        /// 获取计量单位
        /// </summary>
        /// <param name="UnitCode"></param>
        /// <param name="GroupCode"></param>
        /// <returns></returns>
        [WebMethod]
        [SoapHeader("authentication")]
        public ResponseBase<ComputationUnit> GetComputationUnit(string UnitCode, string GroupCode)
        {
            ResponseBase<ComputationUnit> Response = new ResponseBase<ComputationUnit>();
            Response.ErrorInfo = new ErrorMessage();
            Response.Lists = new List<ComputationUnit>();
            Response.ErrorInfo.ErrorCode = 1;
            Response.ErrorInfo.ErrorMsg = "";
            try
            {
                UFDataAccess UFdataContext = new UFDataAccess();
                IQueryable<ComputationUnit> iqueryable = UFdataContext.ComputationUnits;
                if (UnitCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CComunitCode == UnitCode);

                }
                if (GroupCode.Trim().Length > 0)
                {
                    iqueryable = iqueryable.Where(c => c.CGroupCode == GroupCode);
                }
                Response.Lists = iqueryable.ToList();

            }
            catch (Exception ex)
            {

            }

            return Response;
        }




    }
}
